package com.zx.viewlearn.views;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;

import com.zx.viewlearn.R;
import com.zx.viewlearn.model.Point;

import static com.zx.viewlearn.utils.ViewUtils.getMySize;

/**
 *
 */
public class LoadingView1 extends View {
    Paint paint;
    Point mPoint1;

    public LoadingView1(Context context) {
        super(context);
        init();
    }

    public LoadingView1(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        mPoint1 = new Point(20, 20, 20);
        paint = new Paint();
        paint.setColor(getResources().getColor(R.color.colorYellow));
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(getMySize(widthMeasureSpec, 100),
                getMySize(heightMeasureSpec, 100));
    }


    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawCircle(mPoint1.getX(), mPoint1.getY(), mPoint1.getRadius(), paint);

    }

    public void startAnimator() {
//        ValueAnimator mObjectAnimator = ObjectAnimator.ofInt(this, "cx", 20, 80, 20);
//        mObjectAnimator.setRepeatCount(-1);
//        mObjectAnimator.setRepeatMode(ValueAnimator.REVERSE);
////        mObjectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
////            @Override
////            public void onAnimationUpdate(ValueAnimator animation) {
////                invalidate();//重新绘制，会调用onDraw()
////            }
////        });
//        ValueAnimator mObjectAnimator2 = ObjectAnimator.ofInt(this, "cy", 20, 80, 20);
//        mObjectAnimator2.setRepeatCount(-1);
//        mObjectAnimator2.setRepeatMode(ValueAnimator.REVERSE);
//        mObjectAnimator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
//            @Override
//            public void onAnimationUpdate(ValueAnimator animation) {
//                invalidate();//重新绘制，会调用onDraw()
//            }
//        });
//
//
//        AnimatorSet animatorSet = new AnimatorSet();
//        animatorSet.play(mObjectAnimator).with(mObjectAnimator2);
//        animatorSet.setDuration(1000);
//
//        animatorSet.start();
    }
}
